// entity_bullet

local entity_bullet = Assault.Entities:New("entity_bullet")

// On handle physics

function entity_bullet:OnHandlePhysics()
	return false
end

// On entity think

function entity_bullet:OnEntityThink()
	local Rotation = self:EntityGetRotation()
	local Position = self:EntityGetPosition()
	local Creator = self:EntityGetVariable("Creator")
	local Damage = self:EntityGetVariable("Damage")
	local Speed = self:EntityGetVariable("Speed")
	local Force = self:EntityGetVariable("Force")
	
	// Sin and Cos
	
	local Sin = math.sin(math.rad(Rotation)) * Speed
	local Cos = math.cos(math.rad(Rotation)) * Speed
	
	// X and Y
	
	local X = Position.X - Sin
	local Y = Position.Y - Cos
	
	// Vector
	
	local Vector = Assault.Vector:New(X, Y)
	
	// Check for collision
	
	local Collision = self:EntityCheckForCollisions({Creator})
	
	// Check if the new position will collide with any other entities
	
	if (Collision and Collision:EntityGetClass() != "entity_bullet") then
		Collision:EntityDamageHealth(Creator, self, Damage)
		Collision:OnBulletHit(self)
		
		// Set entity force
		
		Collision:EntitySetForce(Rotation, Force)
		
		// Vector
		
		local Vector = Assault.Vector:New(X, Y)
		
		// Damage
		
		Assault.Entities.EntitiesQuickCreate("effect_sparks", Vector, false, Color(50, 50, 50, 255))
		
		// Remove entity
		
		self:EntityRemove()
	else
		self:EntitySetPosition(Vector)
	end
end

// Create

entity_bullet:Create()